using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SM.core;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.func;
namespace TVSGPP.search
{
	public class frmSearchDoctor : Form
	{
		private IContainer components = null;
		private DataGridView dgvProduct;
		private DataGridView dgvCustomer;
		private Button btnClose;
		private GroupBox groupBox1;
		private System.Windows.Forms.TextBox txtSearch;
		private Button btnSearch;
		private Button btnReport;
		private Button btnExportToExcel;
		private System.Windows.Forms.Label label17;
		private DateTimePicker dtpTo;
		private DateTimePicker dtpFrom;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label lblTotalMoney;
		private System.Windows.Forms.Label label2;
		private DataGridViewTextBoxColumn _DoctorName;
		private DataGridViewTextBoxColumn _DoctorAddress;
		private DataGridViewTextBoxColumn _DoctorID;
		private DataGridViewTextBoxColumn _DoctorPhone;
		private DataGridViewTextBoxColumn CreateDate;
		private new DataGridViewTextBoxColumn ProductName;
		private DataGridViewTextBoxColumn SL;
		private DataGridViewTextBoxColumn ProductPrice2;
		private DataGridViewTextBoxColumn ProductMoney;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.TextBox txtProduct;
		private System.Windows.Forms.Label label3;
		private Func objFunc = new Func();
		private Bill objBill = new Bill();
		private DataTable objTable = new DataTable();
		private string currID = "";
		private string DoctorName = "";
		private string DoctorAddress = "";
		private string DoctorPhone = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle6 = new DataGridViewCellStyle();
			ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(frmSearchDoctor));
			this.dgvProduct = new DataGridView();
			this.CreateDate = new DataGridViewTextBoxColumn();
			this.ProductName = new DataGridViewTextBoxColumn();
			this.SL = new DataGridViewTextBoxColumn();
			this.ProductPrice2 = new DataGridViewTextBoxColumn();
			this.ProductMoney = new DataGridViewTextBoxColumn();
			this.dgvCustomer = new DataGridView();
			this._DoctorName = new DataGridViewTextBoxColumn();
			this._DoctorAddress = new DataGridViewTextBoxColumn();
			this._DoctorID = new DataGridViewTextBoxColumn();
			this._DoctorPhone = new DataGridViewTextBoxColumn();
			this.btnClose = new Button();
			this.groupBox1 = new GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.txtProduct = new System.Windows.Forms.TextBox();
			this.label17 = new System.Windows.Forms.Label();
			this.dtpTo = new DateTimePicker();
			this.dtpFrom = new DateTimePicker();
			this.btnSearch = new Button();
			this.label1 = new System.Windows.Forms.Label();
			this.txtSearch = new System.Windows.Forms.TextBox();
			this.btnReport = new Button();
			this.btnExportToExcel = new Button();
			this.lblTotalMoney = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			((ISupportInitialize)this.dgvCustomer).BeginInit();
			this.groupBox1.SuspendLayout();
			base.SuspendLayout();
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.CreateDate,
				this.ProductName,
				this.SL,
				this.ProductPrice2,
				this.ProductMoney
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new System.Drawing.Point(389, 77);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.ReadOnly = true;
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvProduct.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvProduct.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvProduct.Size = new Size(504, 483);
			this.dgvProduct.TabIndex = 40;
			this.CreateDate.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.CreateDate.DataPropertyName = "CreateDate";
			dataGridViewCellStyle2.NullValue = null;
			this.CreateDate.DefaultCellStyle = dataGridViewCellStyle2;
			this.CreateDate.HeaderText = "Ngày xuất";
			this.CreateDate.MinimumWidth = 92;
			this.CreateDate.Name = "CreateDate";
			this.CreateDate.ReadOnly = true;
			this.CreateDate.Width = 92;
			this.ProductName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.ProductName.DataPropertyName = "ProductName";
			this.ProductName.HeaderText = "Tên thuốc";
			this.ProductName.MinimumWidth = 150;
			this.ProductName.Name = "ProductName";
			this.ProductName.ReadOnly = true;
			this.SL.DataPropertyName = "ProductNumber";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.SL.DefaultCellStyle = dataGridViewCellStyle3;
			this.SL.HeaderText = "SL";
			this.SL.MinimumWidth = 60;
			this.SL.Name = "SL";
			this.SL.ReadOnly = true;
			this.SL.Width = 60;
			this.ProductPrice2.DataPropertyName = "ProductPrice2";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.ProductPrice2.DefaultCellStyle = dataGridViewCellStyle4;
			this.ProductPrice2.HeaderText = "Đơn giá";
			this.ProductPrice2.MinimumWidth = 100;
			this.ProductPrice2.Name = "ProductPrice2";
			this.ProductPrice2.ReadOnly = true;
			this.ProductMoney.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.ProductMoney.DataPropertyName = "ProductMoney";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle5.Format = "N0";
			dataGridViewCellStyle5.NullValue = "0";
			this.ProductMoney.DefaultCellStyle = dataGridViewCellStyle5;
			this.ProductMoney.HeaderText = "Thành tiền";
			this.ProductMoney.MinimumWidth = 100;
			this.ProductMoney.Name = "ProductMoney";
			this.ProductMoney.ReadOnly = true;
			this.dgvCustomer.AllowUserToAddRows = false;
			this.dgvCustomer.AllowUserToDeleteRows = false;
			this.dgvCustomer.AllowUserToOrderColumns = true;
			this.dgvCustomer.AllowUserToResizeColumns = false;
			this.dgvCustomer.AllowUserToResizeRows = false;
			dataGridViewCellStyle6.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle6.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvCustomer.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle6;
			this.dgvCustomer.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
			this.dgvCustomer.BackgroundColor = Color.White;
			this.dgvCustomer.BorderStyle = BorderStyle.Fixed3D;
			this.dgvCustomer.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dgvCustomer.Columns.AddRange(new DataGridViewColumn[]
			{
				this._DoctorName,
				this._DoctorAddress,
				this._DoctorID,
				this._DoctorPhone
			});
			this.dgvCustomer.Cursor = Cursors.Hand;
			this.dgvCustomer.EnableHeadersVisualStyles = false;
			this.dgvCustomer.Location = new System.Drawing.Point(7, 110);
			this.dgvCustomer.MultiSelect = false;
			this.dgvCustomer.Name = "dgvCustomer";
			this.dgvCustomer.ReadOnly = true;
			this.dgvCustomer.RowHeadersVisible = false;
			this.dgvCustomer.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvCustomer.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvCustomer.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvCustomer.Size = new Size(376, 450);
			this.dgvCustomer.TabIndex = 41;
			this.dgvCustomer.CellEnter += new DataGridViewCellEventHandler(this.dgvCustomer_CellEnter);
			this._DoctorName.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this._DoctorName.DataPropertyName = "_DoctorName";
			this._DoctorName.HeaderText = "Tên Bác sỹ";
			this._DoctorName.MinimumWidth = 160;
			this._DoctorName.Name = "_DoctorName";
			this._DoctorName.ReadOnly = true;
			this._DoctorName.Width = 160;
			this._DoctorAddress.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this._DoctorAddress.DataPropertyName = "_DoctorAddress";
			this._DoctorAddress.HeaderText = "Địa chỉ";
			this._DoctorAddress.Name = "_DoctorAddress";
			this._DoctorAddress.ReadOnly = true;
			this._DoctorID.DataPropertyName = "_DoctorID";
			this._DoctorID.HeaderText = "ID";
			this._DoctorID.Name = "_DoctorID";
			this._DoctorID.ReadOnly = true;
			this._DoctorID.Visible = false;
			this._DoctorPhone.DataPropertyName = "_DoctorPhone";
			this._DoctorPhone.HeaderText = "Phone";
			this._DoctorPhone.Name = "_DoctorPhone";
			this._DoctorPhone.ReadOnly = true;
			this._DoctorPhone.Visible = false;
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnClose.Cursor = Cursors.Hand;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new System.Drawing.Point(292, 566);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(91, 28);
			this.btnClose.TabIndex = 42;
			this.btnClose.Text = "Thoát  [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.groupBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.txtProduct);
			this.groupBox1.Controls.Add(this.label17);
			this.groupBox1.Controls.Add(this.dtpTo);
			this.groupBox1.Controls.Add(this.dtpFrom);
			this.groupBox1.Controls.Add(this.btnSearch);
			this.groupBox1.Location = new System.Drawing.Point(7, 12);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new Size(886, 58);
			this.groupBox1.TabIndex = 43;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Tìm kiếm theo tên Bác sỹ kê đơn";
			this.label3.BackColor = Color.FromArgb(255, 255, 192);
			this.label3.BorderStyle = BorderStyle.Fixed3D;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label3.Location = new System.Drawing.Point(119, 22);
			this.label3.Name = "label3";
			this.label3.Size = new Size(68, 21);
			this.label3.TabIndex = 158;
			this.label3.Text = "Từ ngày :";
			this.label3.TextAlign = ContentAlignment.MiddleRight;
			this.label4.BackColor = Color.FromArgb(255, 255, 192);
			this.label4.BorderStyle = BorderStyle.Fixed3D;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label4.Location = new System.Drawing.Point(382, 20);
			this.label4.Name = "label4";
			this.label4.Size = new Size(72, 25);
			this.label4.TabIndex = 157;
			this.label4.Text = "Tên thuốc :";
			this.label4.TextAlign = ContentAlignment.MiddleRight;
			this.txtProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.txtProduct.Font = new Font("Arial", 12f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.txtProduct.Location = new System.Drawing.Point(457, 20);
			this.txtProduct.Name = "txtProduct";
			this.txtProduct.Size = new Size(318, 26);
			this.txtProduct.TabIndex = 156;
			this.label17.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
//			this.label17.Image = (Image)componentResourceManager.GetObject("label17.Image");
			this.label17.Location = new System.Drawing.Point(274, 21);
			this.label17.Name = "label17";
			this.label17.Size = new Size(20, 25);
			this.label17.TabIndex = 154;
			this.dtpTo.CustomFormat = "dd/MM/yyyy";
			this.dtpTo.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpTo.Format = DateTimePickerFormat.Custom;
			this.dtpTo.Location = new System.Drawing.Point(295, 22);
			this.dtpTo.Name = "dtpTo";
			this.dtpTo.Size = new Size(81, 21);
			this.dtpTo.TabIndex = 153;
			this.dtpFrom.CustomFormat = "dd/MM/yyyy";
			this.dtpFrom.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.dtpFrom.Format = DateTimePickerFormat.Custom;
			this.dtpFrom.Location = new System.Drawing.Point(190, 22);
			this.dtpFrom.Name = "dtpFrom";
			this.dtpFrom.Size = new Size(81, 21);
			this.dtpFrom.TabIndex = 152;
			this.btnSearch.Anchor = (AnchorStyles.Top | AnchorStyles.Right);
			this.btnSearch.FlatAppearance.BorderColor = Color.MediumTurquoise;
			this.btnSearch.FlatStyle = FlatStyle.Flat;
			this.btnSearch.Font = new Font("Arial", 9f, FontStyle.Bold);
			this.btnSearch.Location = new System.Drawing.Point(781, 19);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new Size(96, 27);
			this.btnSearch.TabIndex = 44;
			this.btnSearch.Text = "Tìm kiếm [ F9 ]";
			this.btnSearch.UseVisualStyleBackColor = true;
			this.btnSearch.Click += new EventHandler(this.btnSearch_Click);
			this.label1.BackColor = Color.FromArgb(255, 255, 192);
			this.label1.BorderStyle = BorderStyle.Fixed3D;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			this.label1.Location = new System.Drawing.Point(7, 77);
			this.label1.Name = "label1";
			this.label1.Size = new Size(115, 26);
			this.label1.TabIndex = 156;
			this.label1.Text = "Tên Bác sỹ kê đơn:";
			this.label1.TextAlign = ContentAlignment.MiddleRight;
			this.txtSearch.Font = new Font("Arial", 12f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.txtSearch.Location = new System.Drawing.Point(126, 78);
			this.txtSearch.Name = "txtSearch";
			this.txtSearch.Size = new Size(257, 26);
			this.txtSearch.TabIndex = 44;
			this.txtSearch.KeyDown += new KeyEventHandler(this.txtSearch_KeyDown);
			this.btnReport.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnReport.Cursor = Cursors.Hand;
			this.btnReport.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnReport.Location = new System.Drawing.Point(7, 566);
			this.btnReport.Name = "btnReport";
			this.btnReport.Size = new Size(96, 28);
			this.btnReport.TabIndex = 44;
			this.btnReport.Text = "Báo cáo  [ F7 ]";
			this.btnReport.UseVisualStyleBackColor = true;
			this.btnReport.Click += new EventHandler(this.btnReport_Click);
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new System.Drawing.Point(103, 566);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(86, 28);
			this.btnExportToExcel.TabIndex = 46;
			this.btnExportToExcel.Text = "Xuất Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			this.lblTotalMoney.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.lblTotalMoney.BackColor = Color.FromArgb(255, 255, 192);
			this.lblTotalMoney.BorderStyle = BorderStyle.Fixed3D;
			this.lblTotalMoney.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.lblTotalMoney.Location = new System.Drawing.Point(790, 568);
			this.lblTotalMoney.Name = "lblTotalMoney";
			this.lblTotalMoney.Size = new Size(103, 26);
			this.lblTotalMoney.TabIndex = 50;
			this.lblTotalMoney.Text = "-:-";
			this.lblTotalMoney.TextAlign = ContentAlignment.MiddleRight;
			this.label2.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.label2.BackColor = Color.FromArgb(255, 255, 192);
			this.label2.BorderStyle = BorderStyle.Fixed3D;
			this.label2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label2.Location = new System.Drawing.Point(389, 568);
			this.label2.Name = "label2";
			this.label2.Size = new Size(398, 26);
			this.label2.TabIndex = 49;
			this.label2.Text = "Tổng tiền :";
			this.label2.TextAlign = ContentAlignment.MiddleRight;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.lblTotalMoney);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.btnReport);
			base.Controls.Add(this.groupBox1);
			base.Controls.Add(this.txtSearch);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.dgvCustomer);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			base.Name = "frmSearchDoctor";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "TÌM KIẾM | BÁC SỸ KÊ ĐƠN";
			base.Load += new EventHandler(this.frmSearchCusFree_Load);
			base.KeyDown += new KeyEventHandler(this.frmSearchCusSale_KeyDown);
			((ISupportInitialize)this.dgvProduct).EndInit();
			((ISupportInitialize)this.dgvCustomer).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmSearchDoctor()
		{
			this.InitializeComponent();
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void getDoctor()
		{
			try
			{
				this.dgvCustomer.AutoGenerateColumns = false;
				this.dgvProduct.DataSource = null;
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				string cmdText;
				if (this.txtSearch.Text.Trim() != "")
				{
					if (this.txtProduct.Text.Trim() == "")
					{
						cmdText = "SELECT [ID] AS _DoctorID, [Name] AS _DoctorName, [Address] AS _DoctorAddress, [Phone] AS _DoctorPhone FROM [TabDoctor] WHERE Upper(Name) LIKE N'%" + this.txtSearch.Text.ToUpper() + "%' AND ID IN (SELECT [_DoctorID] FROM [TabBill] WHERE [TabBill].[CreateDate] BETWEEN @objDate1 AND @objDate2) ORDER BY [Name]";
					}
					else
					{
						cmdText = string.Concat(new string[]
						{
							"SELECT [ID] AS _DoctorID, [Name] AS _DoctorName, [Address] AS _DoctorAddress, [Phone] AS _DoctorPhone FROM [TabDoctor] WHERE Upper(Name) LIKE N'%",
							this.txtSearch.Text.ToUpper(),
							"%' AND ID IN (SELECT [_DoctorID] FROM [TabBill] WHERE [TabBill].[CreateDate] BETWEEN @objDate1 AND @objDate2 AND [ID] IN (SELECT [BillID] FROM [TabDetailBill] WHERE Upper(productName) LIKE N'%",
							this.txtProduct.Text.ToUpper(),
							"%')) ORDER BY [Name]"
						});
					}
				}
				else
				{
					if (this.txtProduct.Text.Trim() == "")
					{
						cmdText = "SELECT [ID] AS _DoctorID, [Name] AS _DoctorName, [Address] AS _DoctorAddress, [Phone] AS _DoctorPhone FROM [TabDoctor] WHERE ID IN (SELECT [_DoctorID] FROM [TabBill] WHERE [TabBill].[CreateDate] BETWEEN @objDate1 AND @objDate2) ORDER BY [Name]";
					}
					else
					{
						cmdText = "SELECT [ID] AS _DoctorID, [Name] AS _DoctorName, [Address] AS _DoctorAddress, [Phone] AS _DoctorPhone FROM [TabDoctor] WHERE ID IN (SELECT [_DoctorID] FROM [TabBill] WHERE [TabBill].[CreateDate] BETWEEN @objDate1 AND @objDate2 AND [ID] IN (SELECT [BillID] FROM [TabDetailBill] WHERE Upper(productName) LIKE N'%" + this.txtProduct.Text.ToUpper() + "%')) ORDER BY [Name]";
					}
				}
				SqlCommand sqlCommand = new SqlCommand(cmdText, sqlConnection);
				SqlParameter sqlParameter = new SqlParameter("ObjDate1", SqlDbType.DateTime);
				SqlParameter sqlParameter2 = new SqlParameter("ObjDate2", SqlDbType.DateTime);
				sqlParameter.Value = DateTime.Parse(this.dtpFrom.Value.ToString().Substring(0, 10) + " 00:00:00 AM");
				sqlParameter2.Value = DateTime.Parse(this.dtpTo.Value.ToString().Substring(0, 10) + " 11:59:59 PM");
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.Parameters.Add(sqlParameter2);
				SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
				DataSet dataSet = new DataSet();
				sqlConnection.Open();
				sqlDataAdapter.Fill(dataSet);
				this.dgvCustomer.DataSource = dataSet.Tables[0];
				sqlConnection.Close();
				sqlConnection.Dispose();
				sqlDataAdapter.Dispose();
				dataSet.Dispose();
				double num = 0.0;
				for (int i = 0; i < this.dgvProduct.Rows.Count; i++)
				{
					num += double.Parse(this.dgvProduct.Rows[i].Cells["ProductMoney"].Value.ToString());
				}
				this.lblTotalMoney.Text = string.Format(Program.lenAffterDecimal, num);
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
		private void frmSearchCusFree_Load(object sender, EventArgs e)
		{
			this.getDoctor();
			this.txtSearch.Focus();
		}
		private void dgvCustomer_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			this.dgvProduct.AutoGenerateColumns = false;
			this.currID = this.dgvCustomer.Rows[e.RowIndex].Cells["_DoctorID"].Value.ToString();
			this.objTable = new DataTable();
			this.objTable = this.objBill.getDetailBillByDoctor(this.currID);
			this.dgvProduct.DataSource = this.objTable;
			double num = 0.0;
			for (int i = 0; i < this.dgvProduct.Rows.Count; i++)
			{
				num += double.Parse(this.dgvProduct.Rows[i].Cells["ProductMoney"].Value.ToString());
			}
			this.lblTotalMoney.Text = string.Format(Program.lenAffterDecimal, num);
			this.DoctorName = this.dgvCustomer.Rows[e.RowIndex].Cells["_DoctorName"].Value.ToString();
			this.DoctorAddress = this.dgvCustomer.Rows[e.RowIndex].Cells["_DoctorAddress"].Value.ToString();
			this.DoctorPhone = this.dgvCustomer.Rows[e.RowIndex].Cells["_DoctorPhone"].Value.ToString();
			this.dgvProduct.Refresh();
		}
		private void btnSearch_Click(object sender, EventArgs e)
		{
			this.getDoctor();
		}
		private void txtSearch_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Return)
			{
				this.btnSearch.PerformClick();
			}
		}
		private void btnReport_Click(object sender, EventArgs e)
		{
		}
		private void frmSearchCusSale_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
			else
			{
				if (e.KeyCode == Keys.F7)
				{
					this.btnReport.PerformClick();
				}
				else
				{
					if (e.KeyCode == Keys.F9)
					{
						this.btnSearch.PerformClick();
					}
				}
			}
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmRepCustomerFreePrint.objTable = new DataTable();
				frmRepCustomerFreePrint.objTable = this.objTable;
				ActiveReport3 activeReport = new frmRepCustomerFreePrint();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
	}
}
